export type SelectOptionValueType =
  | string
  | ReadonlyArray<string>
  | number
  | undefined;
export interface ISelectOption {
  label: string;
  value: SelectOptionValueType;
  type?: string;
  variable?: string[];
}
export interface IToolDropdownOption {
  label: string;
  value: string;
  isActived: boolean;
}
export interface IToolRadioOption {
  label: string;
  value: string;
  isActived: boolean;
  icon?: string;
  disabled?: boolean;
  disabledLabel?: string;
}
export interface IToolSingleButton {
  label: string;
  value: string;
}
export const ConditionType = 'ConditionType';
export interface IMenu {
  id: string;
  items: IMenuItem[];
}
export const ValueMenuSeparator = '$MenuSeparator';
export interface IMenuItem {
  label: string;
  value: string;
  rightSlot?: string; // 一般用于显示快捷键
}
export enum TreeNodeMenuId {
  component = 'component',
  simuCondition = 'simuCondition',
}
export interface ITreeNode {
  id: string;
  label: string;
  isOpen?: boolean;
  type?: TreeNodeType | string;
  iconName?: string;
  action?: string;
  menuId?: string;
  hasForm?: boolean; // 是否有表单可编辑
  formData?: any; // 自己或者祖先节点的表单
  isSet?: boolean; // 是否设置了对应的数据，比如：网格已选，entity已选等，由对应的节点控制
  children?: ITreeNode[];
  extra?: any;
}
export enum TreeNodeType {
  Components = 'Components',
  Component = 'Component',

  Meshes = 'preprocess', // 和后端的数据结构保持一致
  Mesh = 'mesh',
  MeshMeshSize = `${Mesh}-MeshSize`,
  MeshDistribution = `${Mesh}-Distribution`,
  MeshBoundaryLayer = `${Mesh}-BoundaryLayer`,

  MeshControl = 'meshControl',

  Collections = 'collections',
  CollectionsNode = `${Collections}-Node`,
  CollectionsElement = `${Collections}-Element`,
  CollectionsSurface = `${Collections}-Surface`,
  CollectionsReferPoint = `${Collections}-ReferPoint`,

  Simulations = 'simulations',
  Simulation = 'simulation',
  SimulationMesh = `${Simulation}-Mesh`,
  SimulationExpressions = `${Simulation}-Expressions`,
  SimulationMaterials = `${Simulation}-Materials`,
  SimulationBoundaries = `${Simulation}-Boundaries`,
  SimulationInitialization = `${Simulation}-Initialization`,
  SimulationResult = `${Simulation}-Result`,
  SimulationProperties = `${Simulation}-Properties`,
  SimulationParameterUnits = `${Simulation}-ParameterUnits`,

  Tasks = 'tasks',
  Task = 'task',
  TaskMonitor = `${Task}-Monitor`,
  TaskResult = `${Task}-Result`,

  PostProcess = 'postprocess', // 该树节点下包含了“结果”和“可视化”
  Results = 'results',
  Result = 'result',
  Visualizations = 'postprocesses', // 对应到后端保存的postprocesses
  Visualization = 'visualization',
  VisualizationDerived = `${Visualization}-Derived`,
  VisualizationPlot = `${Visualization}-Plot`,
  VisualizationPlotCmd = `${VisualizationPlot}-Cmd`,
}

export type OnMenuItemClick = (node: ITreeNode, menuItem: IMenuItem) => void;

export interface ITreeProps {
  treeData: ITreeNode[];
  menuData?: IMenu[];
  initActive?: ITreeNode;
  onMenuItemClick?: OnMenuItemClick;
  onTreeNodeClick?: (data: ITreeNode) => void;
  onTreeNodeDoubleClick?: (data: ITreeNode) => void;
  readonly?: boolean;
}

export type TreeNodeClickListener = (
  data: ITreeNode,
  onUpdate: (newData: ITreeNode) => void,
) => void;

export type onTreeEventUpdate = (
  newData: ITreeNode,
  menu?: IMenuItem,
  reload?: boolean,
) => void;

export type MenuItemClickListener = (
  data: ITreeNode,
  menu: IMenuItem,
  onUpdate: onTreeEventUpdate,
) => void;

export type VolumeListener = (data: ITreeNode, menu: IMenuItem) => void;

export type ToolbarEventListener = (value: string) => void;

export type ClippingChangeListener = (type: string, value: any) => void;
